//接口地址前缀
var api_base = "http://vip7.chenksoft.com:8080/ckapi/api/4/v2/";
//var api_base = "http://127.0.0.1:8080/ckapi/api/57/v2/";
//获取token
var api_token = api_base+"token.jsp";
//简历主表
var api_resume_info = api_base+"JLZB.jsp";
//工作经历
var api_resume_work = api_base+"GZJY.jsp";
//项目经验
var api_resume_project = api_base+"XMJY.jsp";
//教育经历
var api_resume_edu = api_base+"JXJL.jsp";
//技能特长
var api_resume_skill = api_base+"JNTC.jsp";
//证书
var api_resume_cer = api_base+"ZS.jsp";
//培训经历
var api_resume_train = api_base+"PXJL.jsp";
//附加信息
var api_resume_extra = api_base+"FJXX.jsp";
//校内荣誉
var api_resume_honor = api_base+"XNRY.jsp";
//校内职务
var api_resume_post = api_base+"XNZW.jsp";
//简历列表
var api_resume_list = api_base+"m_qwss.jsp";
var token = "chenksoft!@!";
function getToken(){
	if(token==""){
		//获取简历主表信息
		$.ajax({
			url:api_token,
			type:"post",
			
			data:{},
			success:function(data){
				if(data.code==0){
					token = data.data;
				}
			},
			error:function(e){
				
			}
		})
	}
	return token;
}
function initdata(cid,back){
	//cid="b25135c21edbb38b2b8156136498d1e7";
	var countapi = 5;
	var resume = {};
	//获取简历主表信息
	$.ajax({
		url:api_resume_info,
		type:"post",
		data:{JLBH:cid,token:getToken()},
		success:function(data){
			if(data.code==0&&data.data.length>0){
				var bean = data.data[0];
				resume.name=bean["skt1.skf5"]==null?"":bean["skt1.skf5"];//姓名
				resume.phone=bean["skt1.skf10"]==null?"":bean["skt1.skf10"];//电话
				resume.email=bean["skt1.skf11"]==null?"":bean["skt1.skf11"];//email
				resume.state=bean["skt1.skf13"]==null?"":bean["skt1.skf13"];//求职状态
				resume.sex=bean["skt1.skf6"]==null?"":bean["skt1.skf6"];//性别
				resume.age=bean["skt1.skf7"]==null?"":bean["skt1.skf7"];//年龄
				resume.borth=bean["skt1.skf119"]==null?"":bean["skt1.skf119"];//生日
				resume.addred=bean["skt1.skf150"]==null?"":bean["skt1.skf150"];//地址
				resume.worktime=bean["skt1.skf8"]==null?"":bean["skt1.skf8"];//工作年限
				resume.marriage=bean["skt1.skf148"]==null?"":bean["skt1.skf148"];//婚姻状况
				resume.dereen=bean["skt1.skf19"]==null?"":bean["skt1.skf19"];//最高学历
				resume.introduce=bean["skt1.skf29"]==null?"":bean["skt1.skf29"];//自我介绍
				resume.img=bean["skt1.skf32"]==null?"":bean["skt1.skf32"];//头像
				getwork();//获取工作经历
				getedu();//获取教育经历
				gettrain();//获取培训经历
				getcer();//获取证书
				getskill();//技能
			}else{
				alert("未获取到简历信息");
			}
		},
		error:function(e){
			alert("获取简历异常："+e);
		}
	})
	/**
	 * 工作经历
	 */
	function getwork(){
		$.ajax({
			url:api_resume_work,
			type:"post",
			data:{JLBH:cid,token:getToken()},
			success:function(data){
				if(data.code==0&&data.data.length>0){
					var beans = new Array();
					for(var i=0;i<data.data.length;i++){
						var bean = data.data[i];
						var bean1 = {};
						bean1.companyName = bean["skt2.skf43"]==null?"":bean["skt2.skf43"];//公司名称
						bean1.workDate = bean["skt2.skf39"]==null?"":bean["skt2.skf39"];//开始时间
						bean1.workDateEnd = bean["skt2.skf40"]==null?"":bean["skt2.skf40"];//结束时间					
						bean1.companyNature = bean["skt2.skf52"]==null?"":bean["skt2.skf52"];//公司性质
						bean1.industry = bean["skt2.skf44"]==null?"":bean["skt2.skf44"];//公司行业
						bean1.companySize = bean["skt2.skf51"]==null?"":bean["skt2.skf51"];//公司人数
						bean1.description = bean["skt2.skf53"]==null?"":bean["skt2.skf53"];//公司描述
						bean1.position = bean["skt2.skf41"]==null?"":bean["skt2.skf41"];//职位
						bean1.AnnualSalary = "薪资--";//bean["skt2.skf43"]==null?"":bean["skt2.skf43"];//薪资
						bean1.department = bean["skt2.skf42"]==null?"":bean["skt2.skf42"];//所属部门
						bean1.reporting = bean["skt2.skf55"]==null?"":bean["skt2.skf55"];//汇报对象
						bean1.subordinates = bean["skt2.skf54"]==null?"":bean["skt2.skf54"];//下属人数
						bean1.jobResponsibilities = "";//bean["skt2.skf54"]==null?"":bean["skt2.skf54"];//工作职能
						bean1.workPerformance = bean["skt2.skf57"]==null?"":bean["skt2.skf57"];//工作业绩
						beans[i] = bean1;
					}
					resume.workExperience=beans;
				}
				countapi--;
				if(countapi==0){
					inithtml();
				}
			},
			error:function(e){
				countapi--;
			}
		})
	}
	/**
	 * 教育经历
	 */
	function getedu(){
		$.ajax({
			url:api_resume_edu,
			type:"post",
			data:{JLBH:cid,token:getToken()},
			success:function(data){
				if(data.code==0&&data.data.length>0){
					var beans = new Array();
					for(var i=0;i<data.data.length;i++){
						var bean = data.data[i];
						var bean1 = {};
						bean1.school = bean["skt4.skf74"]==null?"":bean["skt4.skf74"];//毕业学校
						bean1.educationDate = bean["skt4.skf72"]==null?"":bean["skt4.skf72"];//开始时间
						bean1.educationDateEnd = bean["skt4.skf73"]==null?"":bean["skt4.skf73"];//结束时间
						bean1.professional = bean["skt4.skf76"]==null?"":bean["skt4.skf76"];//专业
						bean1.Record = bean["skt4.skf75"]==null?"":bean["skt4.skf75"];//学历
						bean1.isRecruitment = "1";//bean["skt4.skf43"]==null?"":bean["skt4.skf43"];//是否统招
						bean1.content = bean["skt4.skf77"]==null?"":bean["skt4.skf77"];//校内表现
						beans[i] = bean1;
					}
					resume.educationExperience=beans;
				}
				countapi--;
				if(countapi==0){
					inithtml();
				}
			},
			error:function(e){
				countapi--;
			}
		})
	}
	/**
	 * 培训经历
	 */
	function gettrain(){
		$.ajax({
			url:api_resume_train,
			type:"post",
			data:{JLBH:cid,token:getToken()},
			success:function(data){
				if(data.code==0&&data.data.length>0){
					var beans = new Array();
					for(var i=0;i<data.data.length;i++){
						var bean = data.data[i];
						var bean1 = {};
						bean1.schoolname = bean["skt7.skf102"]==null?"":bean["skt7.skf102"];//培训机构名称
						bean1.startDate = bean["skt7.skf100"]==null?"":bean["skt7.skf100"];//开始时间
						bean1.endDate = bean["skt7.skf101"]==null?"":bean["skt7.skf101"];//结束时间
						bean1.content = bean["skt7.skf105"]==null?"":bean["skt7.skf105"];//培训内容
						beans[i] = bean1;
					}
					resume.training=beans;
				}
				countapi--;
				if(countapi==0){
					inithtml();
				}
			},
			error:function(e){
				countapi--;
			}
		})
	}
	/**
	 * 证书
	 */
	function getcer(){
		$.ajax({
			url:api_resume_cer,
			type:"post",
			data:{JLBH:cid,token:getToken()},
			success:function(data){
				if(data.code==0&&data.data.length>0){
					var str = "";
					for(var i=0;i<data.data.length;i++){
						var bean = data.data[i];
						if(i>0){
							str+="<br/>";
						}
						str+=bean["skt6.skf92"]+"&nbsp;&nbsp;&nbsp;"+bean["skt6.skf93"];
					}
					resume.certificate=str;
				}
				countapi--;
				if(countapi==0){
					inithtml();
				}
			},
			error:function(e){
				countapi--;
			}
		})
	}
	/**
	 * 技能
	 */
	function getskill(){
		$.ajax({
			url:api_resume_skill,
			type:"post",
			data:{JLBH:cid,token:getToken()},
			success:function(data){
				if(data.code==0&&data.data.length>0){
					var str = "";
					for(var i=0;i<data.data.length;i++){
						var bean = data.data[i];
						if(i>0){
							str+="<br/>";
						}
						str+=bean["skt5.skf84"]+"&nbsp;&nbsp;&nbsp;"+bean["skt5.skf85"];
					}
					resume.skill=str;
				}
				countapi--;
				if(countapi==0){
					inithtml();
				}
			},
			error:function(e){
				countapi--;
			}
		})
	}
	
	function inithtml(){
		var r = resume;
		//头部信息
		$(".main-head .head-name").text(r.name);//姓名
		$(".main-head .tel").text(r.phone);//电话
		$(".main-head .email").text(r.email);//邮件
		$(".main-head .state").text(finaldata.state(r.state));//工作状态
		$(".main-head .sex").text(finaldata.sex(r.sex));//性别
		$(".main-head .age").text(r.age);//年龄
		$(".main-head .borth").text("("+r.borth+")");//生日
		$(".main-head .addred").text("现居住地："+r.addred+"");//住址
		$(".main-head .worktime").text(""+r.worktime);//住址
		$(".main-head .marriage").text(finaldata.marriage(r.marriage));//婚姻状况
		$(".main-head .dereen").text(""+finaldata.dereen(r.dereen)+"");//最高学历
		
		//自我评价
		$(".content-zwpj .zwpj-left").text(""+r.introduce+"");//自我评价
		$(".content-zwpj .zwpj-right img").prop("src",r.img);//用户头像
		
		//工作经历
		var html_gzjl = $("#temp-gzjl").html();
		var array_gzjl = r.workExperience;
		for(var i=0;array_gzjl!=null&&array_gzjl.length>0&&i<array_gzjl.length;i++){
			var gz = array_gzjl[i];
			$(".content-gzjl").append(html_gzjl);
			var gzjl = $(".content-gzjl .item:last");
			gzjl.find(".time").text(gz.workDate+"至"+(gz.workDateEnd==""?"今":gz.workDateEnd));//工作时间
			gzjl.find(".name").text(gz.companyName);//名称
			gzjl.find(".comp-type .type").text(gz.companyNature);//公司性质
			gzjl.find(".comp-type .trade").text(gz.industry);//行业
			gzjl.find(".comp-type .users").text(gz.companySize);//人数
			gzjl.find(".comp-info").text(gz.description);//公司介绍
			
			gzjl.find(".work-post .depart").text(gz.position);//职位
			gzjl.find(".work-post .time").text(gz.workDate+"至"+(gz.workDateEnd==""?"今":gz.workDateEnd));//就职时间
			gzjl.find(".work-post .money").text(gz.AnnualSalary);//薪资
			if(gz.reporting==null||gz.reporting==""){
				gzjl.find(".work-depart .lader").hide();
			}else{
				gzjl.find(".work-depart .lader").text("汇报对象："+gz.reporting);//汇报对象
			}
			if(gz.subordinates==null||gz.subordinates==0){
				gzjl.find(".work-depart .user").hide();
			}else{
				gzjl.find(".work-depart .user").text("下属人数："+gz.subordinates+"人");//下属人数
			}			
			gzjl.find(".work-depart .eare").text("所属区域：");//区域
			gzjl.find(".work-depart .eare").hide();
			gzjl.find(".work-depart .depart").text("所在部门："+gz.department);//所属部门
			if(gz.jobResponsibilities==null||gz.jobResponsibilities==""){
				gzjl.find(".work-zn .post").parent().hide();
			}else{
				gzjl.find(".work-zn .post").text(gz.jobResponsibilities);//工作职能
			}
			if(gz.workPerformance==null||gz.workPerformance==""){
				gzjl.find(".work-yj .post").parent().hide();
			}else{
				gzjl.find(".work-yj .post").text(gz.workPerformance);//工作业绩
			}
		}
		
		//教育经历
		var html_jyjl = $("#temp-jyjl").html();
		var array_jyjl = r.educationExperience;
		for(var i=0;array_jyjl!=null&&array_jyjl.length>0&&i<array_jyjl.length;i++){			
			var jy = array_jyjl[i];
			console.log(jy);
			$(".content-jyjl").append(html_jyjl);
			var jyjl = $(".content-jyjl .item:last");
			jyjl.find(".name").text("毕业学校："+jy.school);//名称
			jyjl.find(".time").text(jy.educationDate+"至"+jy.educationDateEnd);//名称
			jyjl.find(".major").text("专业："+jy.professional);//名称
			jyjl.find(".degreen").text("学历："+jy.Record);//学历
			jyjl.find(".istz").text("是否统招："+finaldata.isRecruitment(jy.isRecruitment));//是否统招
			if(jy.content==null||jy.content==""){
				jyjl.find(".about").hide();//校内表现
			}else{
				jyjl.find(".about .content").text(jy.content);//校内表现
			}
		}
		//培训经历
		var html_pxjl = $("#temp-pxjl").html();
		var array_pxjl = r.training;
		for(var i=0;array_pxjl!=null&&array_pxjl.length>0&&i<array_pxjl.length;i++){			
			var px = array_pxjl[i];
			console.log(px);
			$(".content-pxjl").append(html_pxjl);
			var pxjl = $(".content-pxjl .item:last");
			pxjl.find(".name").text(""+px.content);//培训内容
			pxjl.find(".time").text(px.startDate+"至"+px.endDate);//时间
			pxjl.find(".about .title").text("培训机构："+px.schoolname);//培训机构
		}
		
		//技能奖励
		$(".content-jnjl .zs").html(r.certificate);//证书
		$(".content-jnjl .jl").html(r.team);//奖励
		//$(".content-jnjl .yy").html(r.english);//语言
		$(".content-jnjl .jn").html(r.skill);//技能
		
		//附加信息
		$(".content-fjxx .other").text(r.other);//其他信息
		
		
		//执行回调方法
		if(back){
			back();
		}
	}
	
}
var finaldata = {
	//性别
	sex:function(key){
		if(key=="1"){
			return "男";
		}else{
			return "女";
		}
	},
	//婚姻
	marriage:function(key){
        if(key=="1"){
            return "未婚";
        }else if(key=="2"){
        	return "已婚";
        }else if(key=="3"){
        	return "离异";
        }else{
        	return "婚姻状态未知";
        }
	},
	//是否为统招
	isRecruitment:function(key){
          if(key=="1"){
          	return "是";
          }else if(key=="0"){
        	  return "否";
          }else{
        	  return "未知"; 
          }
	},
	//最高学历
	dereen:function(key){
        if(key=="1"){
            return "高中";
        }else if(key=="2"){
        	return "大专";
        }else if(key=="3"){
        	return "本科";
        }else if(key=="4"){
        	return "研究生";
        }else if(key=="9"){
        	return "EMBA";
        }else if(key=="10"){
        	return "硕士";
        }else if(key=="12"){
        	return "中技";
        }else{
        	return "高中以下";
        }
	},
	//求职状态
	state:function(key){
		if(key=="1"){
			return "目前在找工作";
		}else if(key=="2"){
			return "我目前在职，正考虑换个新环境";
		}else if(key=="3"){
			return "应届毕业生";
		}else if(key=="4"){
			return "我目前处于离职状态，可立即上岗";
		}else if(key=="5"){
			return "目前暂无跳槽打算";
		}else if(key=="11"){
			return "目前正在找工作";
		}else if(key=="12"){
			return "如有更好的工作机会，我也可以考虑。";
		}else if(key=="13"){
			return "我目前在职，正考虑换个新环境";
		}else{
			return "未知";
		}
	},
}